
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 04/05/2016 11:25:57
-- Generated from EDMX file: D:\Project\svnAnhChuong\LKVMLM\Server\LKVMLMLib\DuAnDaCap.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ieternal];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_CashBankConfig_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CashBankConfig] DROP CONSTRAINT [FK_CashBankConfig_User];
GO
IF OBJECT_ID(N'[dbo].[FK_CommissionMonthYear_CommissionConfig]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CommissionMonthYear] DROP CONSTRAINT [FK_CommissionMonthYear_CommissionConfig];
GO
IF OBJECT_ID(N'[dbo].[FK_Order_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Order] DROP CONSTRAINT [FK_Order_User];
GO
IF OBJECT_ID(N'[dbo].[FK_PerfectMoneyTransaction_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PerfectMoneyTransaction] DROP CONSTRAINT [FK_PerfectMoneyTransaction_User];
GO
IF OBJECT_ID(N'[dbo].[FK_PerfectMoneyUser_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PerfectMoneyUser] DROP CONSTRAINT [FK_PerfectMoneyUser_User];
GO
IF OBJECT_ID(N'[dbo].[FK_PlaceOrder_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PlaceOrder] DROP CONSTRAINT [FK_PlaceOrder_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Profit_Order]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Profit] DROP CONSTRAINT [FK_Profit_Order];
GO
IF OBJECT_ID(N'[dbo].[FK_Share_User_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Share_User] DROP CONSTRAINT [FK_Share_User_User];
GO
IF OBJECT_ID(N'[dbo].[FK_ShareTransaction_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ShareTransaction] DROP CONSTRAINT [FK_ShareTransaction_User];
GO
IF OBJECT_ID(N'[dbo].[FK_U_P]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserProfile] DROP CONSTRAINT [FK_U_P];
GO
IF OBJECT_ID(N'[dbo].[FK_Wallet_Detail_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Wallet_Detail] DROP CONSTRAINT [FK_Wallet_Detail_User];
GO
IF OBJECT_ID(N'[dbo].[FK_WalletHistory_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WalletHistory] DROP CONSTRAINT [FK_WalletHistory_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Withdrawal_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Withdrawal] DROP CONSTRAINT [FK_Withdrawal_User];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Authorized_Code]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Authorized_Code];
GO
IF OBJECT_ID(N'[dbo].[CashBankConfig]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CashBankConfig];
GO
IF OBJECT_ID(N'[dbo].[ChuKyConfig]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ChuKyConfig];
GO
IF OBJECT_ID(N'[dbo].[CommissionConfig]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CommissionConfig];
GO
IF OBJECT_ID(N'[dbo].[CommissionDate]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CommissionDate];
GO
IF OBJECT_ID(N'[dbo].[CommissionMonthYear]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CommissionMonthYear];
GO
IF OBJECT_ID(N'[dbo].[Config]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Config];
GO
IF OBJECT_ID(N'[dbo].[DanhMucTinTuc]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DanhMucTinTuc];
GO
IF OBJECT_ID(N'[dbo].[ExchangeConfig]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ExchangeConfig];
GO
IF OBJECT_ID(N'[dbo].[FeeConfig]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FeeConfig];
GO
IF OBJECT_ID(N'[dbo].[GConfig]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GConfig];
GO
IF OBJECT_ID(N'[dbo].[Group]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Group];
GO
IF OBJECT_ID(N'[dbo].[LocalBank]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LocalBank];
GO
IF OBJECT_ID(N'[dbo].[Order]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Order];
GO
IF OBJECT_ID(N'[dbo].[Package]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Package];
GO
IF OBJECT_ID(N'[dbo].[PaymentMethod]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PaymentMethod];
GO
IF OBJECT_ID(N'[dbo].[PerfectMoneyTransaction]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PerfectMoneyTransaction];
GO
IF OBJECT_ID(N'[dbo].[PerfectMoneyUser]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PerfectMoneyUser];
GO
IF OBJECT_ID(N'[dbo].[Permission]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Permission];
GO
IF OBJECT_ID(N'[dbo].[PhanQuyenWebAdmin]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PhanQuyenWebAdmin];
GO
IF OBJECT_ID(N'[dbo].[PlaceOrder]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PlaceOrder];
GO
IF OBJECT_ID(N'[dbo].[Profit]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Profit];
GO
IF OBJECT_ID(N'[dbo].[Share_User]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Share_User];
GO
IF OBJECT_ID(N'[dbo].[ShareTransaction]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ShareTransaction];
GO
IF OBJECT_ID(N'[dbo].[TinTuc]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TinTuc];
GO
IF OBJECT_ID(N'[dbo].[UserConfig]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserConfig];
GO
IF OBJECT_ID(N'[dbo].[UserLevel]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserLevel];
GO
IF OBJECT_ID(N'[dbo].[UserProfile]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserProfile];
GO
IF OBJECT_ID(N'[dbo].[Wallet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Wallet];
GO
IF OBJECT_ID(N'[dbo].[Wallet_Detail]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Wallet_Detail];
GO
IF OBJECT_ID(N'[dbo].[WalletHistory]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WalletHistory];
GO
IF OBJECT_ID(N'[dbo].[Withdrawal]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Withdrawal];
GO
IF OBJECT_ID(N'[DuAnDaCapModelStoreContainer].[Countries]', 'U') IS NOT NULL
    DROP TABLE [DuAnDaCapModelStoreContainer].[Countries];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Authorized_Code'
CREATE TABLE [dbo].[Authorized_Code] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Code] varchar(50)  NULL,
    [Email] nvarchar(50)  NULL,
    [Createdate] datetime  NULL,
    [During] int  NULL
);
GO

-- Creating table 'ChuKyConfigs'
CREATE TABLE [dbo].[ChuKyConfigs] (
    [ChuKyID] int IDENTITY(1,1) NOT NULL,
    [TenChuKy] nvarchar(50)  NULL,
    [From] int  NULL,
    [To] int  NULL
);
GO

-- Creating table 'CommissionConfigs'
CREATE TABLE [dbo].[CommissionConfigs] (
    [CommissionName] varchar(50)  NOT NULL,
    [CommissionDesc] nvarchar(255)  NULL,
    [Status] bit  NULL,
    [STT] int  NULL,
    [Monthly] bit  NULL,
    [MenuTitle] nvarchar(250)  NULL,
    [MenuLink] varchar(500)  NULL
);
GO

-- Creating table 'CommissionDates'
CREATE TABLE [dbo].[CommissionDates] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [CommissionName] varchar(50)  NULL,
    [Descriptiom] nvarchar(250)  NULL,
    [Date] datetime  NULL,
    [Status] bit  NULL
);
GO

-- Creating table 'CommissionMonthYears'
CREATE TABLE [dbo].[CommissionMonthYears] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [CommissionName] varchar(50)  NULL,
    [Description] nvarchar(250)  NULL,
    [Month] int  NULL,
    [Year] int  NULL,
    [Status] bit  NULL
);
GO

-- Creating table 'Configs'
CREATE TABLE [dbo].[Configs] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Module_Id] varchar(100)  NULL,
    [Module_Name] nvarchar(150)  NULL,
    [Option_1] bit  NULL,
    [Option_2] bit  NULL,
    [Option_3] bit  NULL,
    [Option_4] bit  NULL,
    [Option_5] bit  NULL,
    [Desciption] nvarchar(max)  NULL
);
GO

-- Creating table 'DanhMucTinTucs'
CREATE TABLE [dbo].[DanhMucTinTucs] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(100)  NULL,
    [Status] bit  NULL
);
GO

-- Creating table 'ExchangeConfigs'
CREATE TABLE [dbo].[ExchangeConfigs] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NULL,
    [Value] float  NULL
);
GO

-- Creating table 'FeeConfigs'
CREATE TABLE [dbo].[FeeConfigs] (
    [Id] int  NOT NULL,
    [Addfund] float  NULL,
    [Cashout] float  NULL,
    [BuyStock] float  NULL,
    [SellStock] float  NULL,
    [PremiumEdit] float  NULL
);
GO

-- Creating table 'Groups'
CREATE TABLE [dbo].[Groups] (
    [GroupID] int IDENTITY(1,1) NOT NULL,
    [GroupName] nvarchar(150)  NULL,
    [Default] bit  NULL
);
GO

-- Creating table 'LocalBanks'
CREATE TABLE [dbo].[LocalBanks] (
    [Id] int  NOT NULL,
    [Name] nvarchar(50)  NULL,
    [Balance] float  NULL
);
GO

-- Creating table 'Packages'
CREATE TABLE [dbo].[Packages] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [PackageName] nvarchar(150)  NULL,
    [Price] float  NULL,
    [PackageCode] nvarchar(150)  NULL,
    [PV] int  NULL
);
GO

-- Creating table 'PaymentMethods'
CREATE TABLE [dbo].[PaymentMethods] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NULL,
    [Description] varchar(max)  NULL
);
GO

-- Creating table 'PerfectMoneyUsers'
CREATE TABLE [dbo].[PerfectMoneyUsers] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [PaymentUnit] nvarchar(50)  NULL,
    [Account] nvarchar(50)  NULL,
    [Name] nvarchar(50)  NULL,
    [Payer] nvarchar(50)  NULL,
    [Password] nvarchar(50)  NULL
);
GO

-- Creating table 'Permissions'
CREATE TABLE [dbo].[Permissions] (
    [Permission_ID] int IDENTITY(1,1) NOT NULL,
    [GroupId] int  NULL,
    [Permission_1] bit  NULL,
    [Permission_2] bit  NULL,
    [Permission_3] bit  NULL,
    [Permission_4] bit  NULL,
    [Permission_5] bit  NULL,
    [Permission_6] bit  NULL,
    [Permission_7] bit  NULL,
    [Permission_8] bit  NULL,
    [Permission_9] bit  NULL,
    [Permission_10] bit  NULL
);
GO

-- Creating table 'PhanQuyenWebAdmins'
CREATE TABLE [dbo].[PhanQuyenWebAdmins] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Group_ID] int  NULL,
    [QuyenKichHoatTv] bit  NULL,
    [QuyenThemMoi] bit  NULL,
    [QuyenXoa] bit  NULL,
    [QuyenSuaDuLieu] bit  NULL,
    [QuyenCauHinhHoaHong] bit  NULL,
    [QuyenCauHinhCayHeThong] bit  NULL,
    [QuyenCauHinhThanhVien] bit  NULL,
    [QuyenCauHinhChuKy] bit  NULL,
    [QuyenThanhToan] bit  NULL,
    [QuyenXuatExcel] bit  NULL,
    [QuyenTaoTinTuc] bit  NULL,
    [QuyenCapNhatLogoWebsite] bit  NULL,
    [QuyenDoanhThuLoiNhuan] bit  NULL,
    [QuyenResetData] bit  NULL,
    [QuyenTinhToanHoaHong] bit  NULL,
    [QuyenBacKupDuLieu] bit  NULL,
    [QuyenRestoreDuLieu] bit  NULL,
    [QuyenCauHinhChuyenDoi] bit  NULL,
    [QuyenPhanQuyenHeThong] bit  NULL
);
GO

-- Creating table 'PlaceOrders'
CREATE TABLE [dbo].[PlaceOrders] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [Type] int  NOT NULL,
    [Quantity] int  NOT NULL,
    [UnitPrice] float  NOT NULL,
    [TotalPrice] float  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [Status] int  NOT NULL,
    [WalletId] int  NOT NULL
);
GO

-- Creating table 'Profits'
CREATE TABLE [dbo].[Profits] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NULL,
    [Amount] float  NULL,
    [CreateDate] datetime  NULL,
    [ProfitType] varchar(50)  NULL,
    [Decription] nvarchar(100)  NULL,
    [OrderID] int  NULL,
    [PV] float  NULL,
    [Status] bit  NULL
);
GO

-- Creating table 'Share_User'
CREATE TABLE [dbo].[Share_User] (
    [Balance] float  NOT NULL,
    [UserId] int  NOT NULL
);
GO

-- Creating table 'ShareTransactions'
CREATE TABLE [dbo].[ShareTransactions] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [Type] int  NOT NULL,
    [Quantity] int  NOT NULL,
    [UnitPrice] float  NOT NULL,
    [TotalPrice] float  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [Status] int  NOT NULL
);
GO

-- Creating table 'TinTucs'
CREATE TABLE [dbo].[TinTucs] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [TenBaiViet] nvarchar(250)  NULL,
    [DanhMuc_Id] int  NULL,
    [NoiDung] nvarchar(max)  NULL,
    [NgayTao] datetime  NULL,
    [NguoiTao] nvarchar(70)  NULL,
    [Status] bit  NULL
);
GO

-- Creating table 'UserConfigs'
CREATE TABLE [dbo].[UserConfigs] (
    [Id] int  NOT NULL,
    [AGUsername] bit  NULL,
    [Suffix] varchar(50)  NULL
);
GO

-- Creating table 'UserLevels'
CREATE TABLE [dbo].[UserLevels] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NULL,
    [Amount] float  NULL,
    [Maximum] float  NOT NULL,
    [Minimum] float  NOT NULL
);
GO

-- Creating table 'Wallets'
CREATE TABLE [dbo].[Wallets] (
    [Id] int  NOT NULL,
    [Name] nvarchar(50)  NULL,
    [Withdraw] bit  NULL
);
GO

-- Creating table 'Wallet_Detail'
CREATE TABLE [dbo].[Wallet_Detail] (
    [UserID] int  NOT NULL,
    [WalletID] int  NOT NULL,
    [Balance] float  NOT NULL
);
GO

-- Creating table 'WebsiteConfigs'
CREATE TABLE [dbo].[WebsiteConfigs] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Footer] nvarchar(max)  NULL,
    [Link] varchar(max)  NULL,
    [Color] varchar(50)  NULL,
    [Title] nvarchar(max)  NULL
);
GO

-- Creating table 'Withdrawals'
CREATE TABLE [dbo].[Withdrawals] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NULL,
    [WalletId] int  NULL,
    [Create_Date] datetime  NULL,
    [Amout] float  NULL,
    [Payment_Method] int  NULL,
    [Status] int  NULL
);
GO

-- Creating table 'GConfigs'
CREATE TABLE [dbo].[GConfigs] (
    [Id] int  NOT NULL,
    [ROI] float  NULL,
    [isMaintainent] bit  NULL,
    [PenddingWallet] bit  NULL
);
GO

-- Creating table 'CashBankConfigs'
CREATE TABLE [dbo].[CashBankConfigs] (
    [UserId] int  NOT NULL,
    [Type] varchar(50)  NULL,
    [Percent] float  NULL
);
GO

-- Creating table 'PerfectMoneyTransactions'
CREATE TABLE [dbo].[PerfectMoneyTransactions] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [Payee_Account] nvarchar(50)  NULL,
    [Payee_Name] nvarchar(50)  NULL,
    [Payment_Amount] float  NOT NULL,
    [Payment_Units] nvarchar(50)  NOT NULL,
    [Payment_Batch_Num] nvarchar(50)  NULL,
    [Payment_Status] nvarchar(50)  NULL,
    [Payer_Account] nvarchar(50)  NULL,
    [Order_Num] nvarchar(50)  NULL,
    [Cust_Num] nvarchar(50)  NULL,
    [Interface_Language] nvarchar(10)  NULL,
    [V2_Hash] nvarchar(100)  NULL,
    [TimeStampgmt] nvarchar(100)  NULL,
    [Create_Date] datetime  NULL,
    [Modifi_Date] datetime  NULL
);
GO

-- Creating table 'Countries'
CREATE TABLE [dbo].[Countries] (
    [NumericalCode] char(3)  NOT NULL,
    [CountryNameLowerCase] nvarchar(50)  NOT NULL,
    [CountryNameUpperCase] nvarchar(50)  NOT NULL,
    [ISO_ALPHA3] char(3)  NOT NULL,
    [ISO_ALPHA2] char(2)  NOT NULL
);
GO

-- Creating table 'UserProfiles'
CREATE TABLE [dbo].[UserProfiles] (
    [UserId] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(max)  NULL,
    [GruopID] int  NULL,
    [Parent_ID] int  NULL,
    [ParentB_ID] int  NULL,
    [Left] int  NULL,
    [Right] int  NULL,
    [HOTEN] nvarchar(255)  NULL,
    [GIOITINH] nvarchar(50)  NULL,
    [HOTENVOHOACCHONG] nvarchar(255)  NULL,
    [MSTCANHAN] varchar(max)  NULL,
    [NGAYSINH] datetime  NULL,
    [NOISINH] nvarchar(100)  NULL,
    [DIACHI] nvarchar(255)  NULL,
    [THANHPHO] nvarchar(255)  NULL,
    [QUOCGIA] nvarchar(100)  NULL,
    [SOCMND] varchar(50)  NULL,
    [NGAYCAP] datetime  NULL,
    [NOICAP] nvarchar(150)  NULL,
    [EMAIL] nvarchar(150)  NULL,
    [SDTNHARIENG] varchar(max)  NULL,
    [SDTNOILAMVIEC] varchar(max)  NULL,
    [SCMNDCUAVOHOACCHONG] varchar(50)  NULL,
    [Password] nvarchar(128)  NULL,
    [CreateDate] datetime  NULL,
    [Level] int  NULL,
    [Status] bit  NULL,
    [PackageID] int  NULL,
    [HoanVon] float  NULL,
    [PreLevel] int  NULL,
    [LevelUpdate] datetime  NULL,
    [SoTaiKhoan] varchar(max)  NULL,
    [NganHang] nvarchar(150)  NULL,
    [p] varchar(50)  NULL,
    [DatDuoiKH] int  NULL
);
GO

-- Creating table 'Orders'
CREATE TABLE [dbo].[Orders] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [ID_Order] nvarchar(150)  NULL,
    [UserId] int  NULL,
    [Amount] float  NULL,
    [Date] datetime  NULL,
    [Action] bit  NULL,
    [Package_id] int  NULL,
    [IsFirst] bit  NULL,
    [Pv] int  NULL,
    [numpackage] int  NULL,
    [Description] nvarchar(1000)  NULL,
    [Percent] float  NULL
);
GO

-- Creating table 'WalletHistories'
CREATE TABLE [dbo].[WalletHistories] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [UserId] int  NOT NULL,
    [Amount] float  NULL,
    [Description] nvarchar(500)  NULL,
    [Payment_orderid] varchar(100)  NULL,
    [WalletId] int  NULL,
    [PaymentMethod] int  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Authorized_Code'
ALTER TABLE [dbo].[Authorized_Code]
ADD CONSTRAINT [PK_Authorized_Code]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [ChuKyID] in table 'ChuKyConfigs'
ALTER TABLE [dbo].[ChuKyConfigs]
ADD CONSTRAINT [PK_ChuKyConfigs]
    PRIMARY KEY CLUSTERED ([ChuKyID] ASC);
GO

-- Creating primary key on [CommissionName] in table 'CommissionConfigs'
ALTER TABLE [dbo].[CommissionConfigs]
ADD CONSTRAINT [PK_CommissionConfigs]
    PRIMARY KEY CLUSTERED ([CommissionName] ASC);
GO

-- Creating primary key on [ID] in table 'CommissionDates'
ALTER TABLE [dbo].[CommissionDates]
ADD CONSTRAINT [PK_CommissionDates]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'CommissionMonthYears'
ALTER TABLE [dbo].[CommissionMonthYears]
ADD CONSTRAINT [PK_CommissionMonthYears]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Configs'
ALTER TABLE [dbo].[Configs]
ADD CONSTRAINT [PK_Configs]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'DanhMucTinTucs'
ALTER TABLE [dbo].[DanhMucTinTucs]
ADD CONSTRAINT [PK_DanhMucTinTucs]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ExchangeConfigs'
ALTER TABLE [dbo].[ExchangeConfigs]
ADD CONSTRAINT [PK_ExchangeConfigs]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Id] in table 'FeeConfigs'
ALTER TABLE [dbo].[FeeConfigs]
ADD CONSTRAINT [PK_FeeConfigs]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [GroupID] in table 'Groups'
ALTER TABLE [dbo].[Groups]
ADD CONSTRAINT [PK_Groups]
    PRIMARY KEY CLUSTERED ([GroupID] ASC);
GO

-- Creating primary key on [Id] in table 'LocalBanks'
ALTER TABLE [dbo].[LocalBanks]
ADD CONSTRAINT [PK_LocalBanks]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [ID] in table 'Packages'
ALTER TABLE [dbo].[Packages]
ADD CONSTRAINT [PK_Packages]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Id] in table 'PaymentMethods'
ALTER TABLE [dbo].[PaymentMethods]
ADD CONSTRAINT [PK_PaymentMethods]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PerfectMoneyUsers'
ALTER TABLE [dbo].[PerfectMoneyUsers]
ADD CONSTRAINT [PK_PerfectMoneyUsers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Permission_ID] in table 'Permissions'
ALTER TABLE [dbo].[Permissions]
ADD CONSTRAINT [PK_Permissions]
    PRIMARY KEY CLUSTERED ([Permission_ID] ASC);
GO

-- Creating primary key on [ID] in table 'PhanQuyenWebAdmins'
ALTER TABLE [dbo].[PhanQuyenWebAdmins]
ADD CONSTRAINT [PK_PhanQuyenWebAdmins]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Id] in table 'PlaceOrders'
ALTER TABLE [dbo].[PlaceOrders]
ADD CONSTRAINT [PK_PlaceOrders]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [ID] in table 'Profits'
ALTER TABLE [dbo].[Profits]
ADD CONSTRAINT [PK_Profits]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [UserId] in table 'Share_User'
ALTER TABLE [dbo].[Share_User]
ADD CONSTRAINT [PK_Share_User]
    PRIMARY KEY CLUSTERED ([UserId] ASC);
GO

-- Creating primary key on [Id] in table 'ShareTransactions'
ALTER TABLE [dbo].[ShareTransactions]
ADD CONSTRAINT [PK_ShareTransactions]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [ID] in table 'TinTucs'
ALTER TABLE [dbo].[TinTucs]
ADD CONSTRAINT [PK_TinTucs]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Id] in table 'UserConfigs'
ALTER TABLE [dbo].[UserConfigs]
ADD CONSTRAINT [PK_UserConfigs]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserLevels'
ALTER TABLE [dbo].[UserLevels]
ADD CONSTRAINT [PK_UserLevels]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Wallets'
ALTER TABLE [dbo].[Wallets]
ADD CONSTRAINT [PK_Wallets]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [UserID], [WalletID] in table 'Wallet_Detail'
ALTER TABLE [dbo].[Wallet_Detail]
ADD CONSTRAINT [PK_Wallet_Detail]
    PRIMARY KEY CLUSTERED ([UserID], [WalletID] ASC);
GO

-- Creating primary key on [Id] in table 'WebsiteConfigs'
ALTER TABLE [dbo].[WebsiteConfigs]
ADD CONSTRAINT [PK_WebsiteConfigs]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Withdrawals'
ALTER TABLE [dbo].[Withdrawals]
ADD CONSTRAINT [PK_Withdrawals]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'GConfigs'
ALTER TABLE [dbo].[GConfigs]
ADD CONSTRAINT [PK_GConfigs]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [UserId] in table 'CashBankConfigs'
ALTER TABLE [dbo].[CashBankConfigs]
ADD CONSTRAINT [PK_CashBankConfigs]
    PRIMARY KEY CLUSTERED ([UserId] ASC);
GO

-- Creating primary key on [Id] in table 'PerfectMoneyTransactions'
ALTER TABLE [dbo].[PerfectMoneyTransactions]
ADD CONSTRAINT [PK_PerfectMoneyTransactions]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [NumericalCode], [CountryNameLowerCase], [CountryNameUpperCase], [ISO_ALPHA3], [ISO_ALPHA2] in table 'Countries'
ALTER TABLE [dbo].[Countries]
ADD CONSTRAINT [PK_Countries]
    PRIMARY KEY CLUSTERED ([NumericalCode], [CountryNameLowerCase], [CountryNameUpperCase], [ISO_ALPHA3], [ISO_ALPHA2] ASC);
GO

-- Creating primary key on [UserId] in table 'UserProfiles'
ALTER TABLE [dbo].[UserProfiles]
ADD CONSTRAINT [PK_UserProfiles]
    PRIMARY KEY CLUSTERED ([UserId] ASC);
GO

-- Creating primary key on [ID] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [PK_Orders]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'WalletHistories'
ALTER TABLE [dbo].[WalletHistories]
ADD CONSTRAINT [PK_WalletHistories]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [CommissionName] in table 'CommissionMonthYears'
ALTER TABLE [dbo].[CommissionMonthYears]
ADD CONSTRAINT [FK_CommissionMonthYear_CommissionConfig]
    FOREIGN KEY ([CommissionName])
    REFERENCES [dbo].[CommissionConfigs]
        ([CommissionName])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_CommissionMonthYear_CommissionConfig'
CREATE INDEX [IX_FK_CommissionMonthYear_CommissionConfig]
ON [dbo].[CommissionMonthYears]
    ([CommissionName]);
GO

-- Creating foreign key on [UserId] in table 'CashBankConfigs'
ALTER TABLE [dbo].[CashBankConfigs]
ADD CONSTRAINT [FK_CashBankConfig_User]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserProfiles]
        ([UserId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [PackageID] in table 'UserProfiles'
ALTER TABLE [dbo].[UserProfiles]
ADD CONSTRAINT [FK_U_P]
    FOREIGN KEY ([PackageID])
    REFERENCES [dbo].[Packages]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_U_P'
CREATE INDEX [IX_FK_U_P]
ON [dbo].[UserProfiles]
    ([PackageID]);
GO

-- Creating foreign key on [UserId] in table 'PerfectMoneyTransactions'
ALTER TABLE [dbo].[PerfectMoneyTransactions]
ADD CONSTRAINT [FK_PerfectMoneyTransaction_User]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserProfiles]
        ([UserId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_PerfectMoneyTransaction_User'
CREATE INDEX [IX_FK_PerfectMoneyTransaction_User]
ON [dbo].[PerfectMoneyTransactions]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'PerfectMoneyUsers'
ALTER TABLE [dbo].[PerfectMoneyUsers]
ADD CONSTRAINT [FK_PerfectMoneyUser_User]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserProfiles]
        ([UserId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_PerfectMoneyUser_User'
CREATE INDEX [IX_FK_PerfectMoneyUser_User]
ON [dbo].[PerfectMoneyUsers]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'PlaceOrders'
ALTER TABLE [dbo].[PlaceOrders]
ADD CONSTRAINT [FK_PlaceOrder_User]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserProfiles]
        ([UserId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_PlaceOrder_User'
CREATE INDEX [IX_FK_PlaceOrder_User]
ON [dbo].[PlaceOrders]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'Share_User'
ALTER TABLE [dbo].[Share_User]
ADD CONSTRAINT [FK_Share_User_User]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserProfiles]
        ([UserId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [UserId] in table 'ShareTransactions'
ALTER TABLE [dbo].[ShareTransactions]
ADD CONSTRAINT [FK_ShareTransaction_User]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserProfiles]
        ([UserId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_ShareTransaction_User'
CREATE INDEX [IX_FK_ShareTransaction_User]
ON [dbo].[ShareTransactions]
    ([UserId]);
GO

-- Creating foreign key on [UserID] in table 'Wallet_Detail'
ALTER TABLE [dbo].[Wallet_Detail]
ADD CONSTRAINT [FK_Wallet_Detail_User]
    FOREIGN KEY ([UserID])
    REFERENCES [dbo].[UserProfiles]
        ([UserId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [UserId] in table 'Withdrawals'
ALTER TABLE [dbo].[Withdrawals]
ADD CONSTRAINT [FK_Withdrawal_User]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserProfiles]
        ([UserId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_Withdrawal_User'
CREATE INDEX [IX_FK_Withdrawal_User]
ON [dbo].[Withdrawals]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [FK_Order_User]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserProfiles]
        ([UserId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_Order_User'
CREATE INDEX [IX_FK_Order_User]
ON [dbo].[Orders]
    ([UserId]);
GO

-- Creating foreign key on [OrderID] in table 'Profits'
ALTER TABLE [dbo].[Profits]
ADD CONSTRAINT [FK_Profit_Order]
    FOREIGN KEY ([OrderID])
    REFERENCES [dbo].[Orders]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_Profit_Order'
CREATE INDEX [IX_FK_Profit_Order]
ON [dbo].[Profits]
    ([OrderID]);
GO

-- Creating foreign key on [UserId] in table 'WalletHistories'
ALTER TABLE [dbo].[WalletHistories]
ADD CONSTRAINT [FK_WalletHistory_User]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserProfiles]
        ([UserId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_WalletHistory_User'
CREATE INDEX [IX_FK_WalletHistory_User]
ON [dbo].[WalletHistories]
    ([UserId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------